#include<bits/stdc++.h>
using namespace std;
#define int long long
int tt,n,a[100001],dp[100001][2][2],sum[101],ans;
signed main()
{
	freopen("color.in","r",stdin);
	freopen("color.out","w",stdout);
	cin>>tt;
	while(tt--)
	{
		cin>>n;ans=0;
		for(int i=1;i<=n;i++) cin>>a[i],sum[i]=sum[i-1]+(a[i]==a[i-1])*a[i];
		memset(dp,0,sizeof(dp));
		dp[2][1][0]=dp[2][0][1]=0,dp[2][0][0]=dp[2][1][1]=(a[2]==a[1])*a[1];
		for(int i=3;i<=n;i++)
		{
			dp[i][0][0]=max(dp[i-1][0][1],dp[i-1][0][0])+(a[i]==a[i-1])*a[i];
			dp[i][1][1]=max(dp[i-1][1][0],dp[i-1][1][1])+(a[i]==a[i-1])*a[i];
			for(int j=2;j<i-1;j++)
			{
				dp[i][0][1]=max(dp[i][0][1],dp[j][0][1]+(a[i]==a[j])*a[i]+sum[i-1]-sum[j+1]+(a[j+1]==a[j-1])*a[j-1]);
				dp[i][0][1]=max(dp[i][0][1],dp[j][0][0]+(a[i]==a[j])*a[i]+sum[i-1]-sum[j+1]);
				dp[i][1][0]=max(dp[i][1][0],dp[j][1][0]+(a[i]==a[j])*a[i]+sum[i-1]-sum[j+1]+(a[j+1]==a[j-1])*a[j-1]);
				dp[i][1][0]=max(dp[i][1][0],dp[j][1][1]+(a[i]==a[j])*a[i]+sum[i-1]-sum[j+1]);
			}
			dp[i][0][1]=max(dp[i][0][1],sum[i-1]+(a[i]==a[1])*a[i]);
			dp[i][1][0]=max(dp[i][1][0],sum[i-1]+(a[i]==a[1])*a[i]);
			ans=max(ans,max(dp[i][0][0],max(dp[i][1][0],max(dp[i][1][1],dp[i][0][0]))));
		}
		cout<<ans<<"\n";
	}
	return 0;
}
